<template>
  <el-card class="table-card" v-loading="pageLoading">
    <h3 slot="header">供应商考察工作评价标准</h3>
    <BasicTable
      :showSelectCol="false"
      :showPagination="false"
      :isShowTooltip="false"
      :span-method="targetSpanMethod"
      :columns="targetInfo.columns"
      :dataSource="targetInfo.list"
    />
    <BasicTable
      :showSelectCol="false"
      :showPagination="false"
      :isShowTooltip="false"
      :showHeader="false"
      :span-method="arrangementSpanMethod"
      :columns="arrangementInfo.columns"
      :dataSource="arrangementInfo.list"
    />
    <BasicTable
      :showSelectCol="false"
      :showPagination="false"
      :isShowTooltip="false"
      :showHeader="false"
      :columns="otherInfo.columns"
      :dataSource="otherInfo.list"
    />
    <BasicTable
      :showSelectCol="false"
      :showPagination="false"
      :isShowTooltip="false"
      :showHeader="false"
      :columns="footerInfo.columns"
      :dataSource="footerInfo.list"
    />
    <el-row class="footer" type="flex" justify="center">
      <el-button @click="handleGoBack">返回上一层</el-button>
    </el-row>
  </el-card>
</template>
<script>
import BasicTable from '@/components/supplier/BasicTable';
import { queryReportEvaluationService } from '@api/supplier/returnVisteManage';
import { list2Obj } from '@/pages/supplier/utils';
import { MARK_OPTIONS } from '../constants'

export default {
  components: {
    BasicTable,
  },
  data () {
    return {
      pageLoading: false,
      targets: [],
      targetInfo: {
        list: [],
        columns: [
          {
            title: '分类',
            key: 'category',
            fixedWidth: 160
          },
          {
            title: '评价维度',
            key: 'categoryx',
            fixedWidth: 240,
            children: [
              {
                title: '考察目的',
                key: 'inspectTarget',
                fixedWidth: 120,
              },
              {
                title: '考察目的数量',
                key: 'account',
                fixedWidth: 120,
              },
            ]
          },
          {
            title: '权重(90)',
            key: 'weight',
            fixedWidth: 80
          },
          {
            title: '评分标准',
            key: 'standard',
            align: 'left',
            render: (h, { row }) => {
              return <div>
                <p>1.按照单项考察目的，完成考察目的目标值，得分100%；</p>
                <p>2.按照单项考察目的，未达到目标值，但较原情况有所提高改善的，按照以下原则下评分：</p>
                <ul style="margin-left: 24px">
                  <li>瓶颈供应商：得分75%；</li>
                  <li>战略供应商：得分70%；</li>
                  <li>核心供应商：得分60%；</li>
                  <li>一般供应商：得分50%；</li>
                </ul>
                <p>3.按照单项考察目的，较原情况无任何改善的，得分0。</p>
              </div>
            }
          },
          {
            title: '评分项',
            key: 'mark',
            formatter: (row, columns, cellValue) => {
              return list2Obj(MARK_OPTIONS)[cellValue]
            }
          },
          {
            title: '得分',
            key: 'score',
            fixedWidth: 80
          },
        ],
      },
      arrangementInfo: {
        list: [
          {
            id: '12987122',
            category: '考察工作安排评价',
            target: '计划执行是否及时',
            weight: 10,
            standard: '按照实际情况，上级领导评分。',
            score: 0,
          },
          {
            id: '12987123',
            category: '考察工作安排评价',
            target: '计划行程安排是否合理',
          },
          {
            id: '12987124',
            category: '考察工作安排评价',
            target: '考察人员报告内容是否详尽',
          },
        ],
        columns: [
          {
            title: '分类',
            key: 'category',
            fixedWidth: 160
          },
          {
            title: '评价维度',
            key: 'target',
            fixedWidth: 240,
          },
          {
            title: '权重',
            key: 'weight',
            fixedWidth: 80
          },
          {
            title: '评分标准',
            key: 'standard',
            align: 'left',
          },
          {
            title: '得分',
            key: 'score',
            fixedWidth: 240,
          },
        ]
      },
      otherInfo: {
        list: [
          {
            id: '12987112',
            category: '加分项',
            weight: '/',
            standard: '超预期完成考察目标的，直接上级按照实际情况给与加分，加分不得超过20分。',
            score: 0,
          },
          {
            id: '12987113',
            category: '重大事项扣分',
            weight: '/',
            standard: '考察人员考察期间是否出现不当行为（不当行为包含不限于：接受超标准宴请，虚假报账，实际未现场考察等廉政问题），上级领导根据实际情况给与不低于30分的扣分。',
            score: 0,
          },
        ],
        columns: [
          {
            title: '分类',
            key: 'category',
            fixedWidth: 400
          },
          {
            title: '权重',
            key: 'weight',
            fixedWidth: 80
          },
          {
            title: '评分标准',
            key: 'standard',
            align: 'left',
          },
          {
            title: '得分',
            key: 'score',
            fixedWidth: 240,
          },
        ]
      },
      footerInfo: {
        list: [
          {
            category: '考察工作最终得分',
            score: '',
          },
        ],
        columns: [
          {
            title: '分类',
            key: 'category',
          },
          {
            title: '得分',
            key: 'score',
            fixedWidth: 240
          },
        ]
      },
    };
  },
  created () {
    this.queryReportEvaluation();
  },
  methods: {
    async queryReportEvaluation () {
      const { planId, reportId, supplierId } = this.$route.query;
      const res = await queryReportEvaluationService(
        { planId, reportId, supplierId },
        state => { this.pageLoading = state }
      )
      if (res) {
        const {
          cooperativeClassify, // 供应商伙伴关系
          inspectTargetVO, // 考察目标
          inspectWork, // 考察工作安排
          bonusPoint, // 加分项
          deduction, // 重大事项扣分
          finalScore, // 考察工作最终得分
        } = res.result;
        this.cooperativeClassify = cooperativeClassify;
        this.targets = inspectTargetVO;
        this.arrangementInfo.list[0].score = inspectWork;
        this.otherInfo.list[0].score = bonusPoint;
        this.otherInfo.list[1].score = deduction;
        this.footerInfo.list[0].score = finalScore;
        this.initTargetTable()
      }
    },
    initTargetTable () {
      this.targetInfo.list = this.targets.map(item => ({
        category: '考察目标完成情况评价',
        inspectTarget: item.inspectTarget,
        account: this.targets.length,
        weight: 90 / this.targets.length,
        standard: '',
        mark: item.mark,
        score: item.score,
      }))
    },
    targetSpanMethod ({ row, column, rowIndex, columnIndex }) {
      if ([0, 2, 4].includes(columnIndex)) {
        if (rowIndex == 0) {
          return {
            rowspan: this.targetInfo.list.length + 1,
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
    },
    arrangementSpanMethod ({ row, column, rowIndex, columnIndex }) {
      if ([0, 2, 3, 4].includes(columnIndex)) {
        if (rowIndex == 0) {
          return {
            rowspan: this.arrangementInfo.list.length + 1,
            colspan: 1
          };
        } else {
          return {
            rowspan: 0,
            colspan: 0
          };
        }
      }
    },
    // 返回上一层
    handleGoBack () {
      this.$router.go(-1)
    }
  }
};
</script>
<style scoped>
.footer {
  margin-top: 10px;
}
</style>
